Razor basic syntax 1: Razor basic syntax
Directory:
What is Razor?
Rendering HTML
Razor syntax
Implicit Razor expression
Explicit Razor expression
What is Razor?
First, Razor grammar1. Razor identifierExplanation: The @ character is defined as the identifier of the Razor server code block, followed by the server code. It is a good idea to use @{ String userName = "Kai Super"; span > My name is: @userNamespan> span > My date of birth: @DateTime. Now.tostring ("Yyyy-mm-dd"); span >
Razor, razor
When learning MVC, you will always see the default Razor when creating a controller:
Then, we can write the following in the created View:
So what are the things with @ That don't look like html but put on The View? Let's start from the beginning ~~
1. What is Razor
Razor Exercise 4, razor exercise
Practice Razor's logic processing today. Generally, the following
1. if
2. else
3. else if
4. switch
In the following demonstration, Insus. NET demonstrates 1, 2, and 4 respectively:The xxx. cshtml code is as follows:@ {Layout = null; string laborDay = ""; string name = "Insus. NET "; string [] colors = {" ff0000 "," 0000ff "," 00ff00 "}; // red, blue, green} Animation demo
The key is to output JS on the plain text content, so that the browser to parse the JS code@: Indicates the direct output string afterEither way, note that MVC Razor with JavaScript (embedded razor in JS)
Razor and razorPreface:
The core of the Razor engine is to identify the @ symbol and angle brackets:1. 2. [For more information, see the example below.]
@for (int i = 0; i
{
}
Basic Syntax: Syntax 1 ,@()
Expression
@ (1 = 0? "1 equals 0": "1 not equal to 0 ")
Syntax 2 ,@{}
Statement Block
@{
var now = DateTime.Now;
if (now.Hour.CompareTo(12)
{
}
else
{
}
}
Use ajax to partially update the Razor page and ajax to partially update the razor page
Razor is very powerful, but it cannot be refreshed. Therefore, it must be used with ajax.
This article provides a simple example to achieve local refresh through Razor and ajax.
First, create an MVC Project
Let's create a simple Co
Some methods of link in Razor syntax, razor syntax Link
In Razor, there are HTML. ActionLink and Url. Action to render the link. What are their differences. If you can clearly distinguish them, you will know under what circumstances to use them.First, let's take a look at html. ActionLink. This method loads a lot and generates a If no controller is specified, the
Razor Exercise 2, razor exercise
Razor data types include string, int, float, decimal, and bool.In addition, data type conversion is required. The common methods are as follows:ToString (): converts the data type to string ). This is the same as the C # syntax.IsBool () and AsBool () convert strings to Boolean values ).IsFloat () and AsFloat () convert strings t
Razor Exercise 3, razor exercise
In Razor syntax, it uses three types of material loop processing: for, while, and foreach.
The following Insus. NET illustrates an example in the ASP. net mvc environment by appending the source code:While: Animation demonstration:
Forced conversion of the razor type and forced conversion of the razor type
1. If the background obtains a List type
1. Obtain array data in the background
Var dutyList = IOCFactory. R ViewBag. dutyList = dutyList;
2. Front-end cyclic binding drop-down box
@ Foreach (Object item in ViewBag. dutyList){}
2. If the backend obtains a List
1. Obtain the object array type in the background
List ViewBag. dutyLis
ASP. NET Core Chinese Document Chapter 4 MVC (3.2) Razor syntax reference, mvcrazor
Original article: Razor Syntax ReferenceBy Taylor Mullen and Rick AndersonTranslation: Liu Yi (AlexLEWIS)Proofreader: He zhenghouWhat is Razor?
Razor is a tag syntax that can be converted to web pages based on server code. The
Original: Razor Syntax ReferenceTaylor Mullen, Rick AndersonTranslation: Liu Yi (alexlewis)Proofreading: He ShiodomeWhat is Razor?Razor is a markup syntax that can be converted to a Web page based on server-side code. The Razor syntax consists of Razor tags, C #, and HTML. F
").val(), PassWord: $("#PassWord").val() }, success: function (response) { console.log(response); }, failure: function (response) { alert(response); } }); });The modified code adds a "Xsrf-token" ID to the request header before sending the request, and the value is the auto-generated security token for the form. Since "Xsrf-token" is our
ArticleDirectory
Design Objectives
Flexible selection space
Razor "Hello World"
Layout Design/master page-Basics
Layout Design page/master page-overwrite some content
Encapsulate and reuse HTML auxiliary functions
Support for Visual Studio
Summary
[Original article] introducing "Razor"-A New View engine for ASP. NET
[Original article publication date] July 02,201 0 pm
One of the jobs my team is currently working on is adding a new view engine for ASP.All along, ASP. NET MVC supports the concept of a "view engine"-a pluggable module with a template of different syntax. The current ASP. NET MVC "default" View engine is the. aspx/.ascx/.master file template used by ASP. Some of the other popular ASP. NET MVC View engines today include spark and Nhaml.We are building a new view engine that is optimized for HTML generation with a code-focused template solution. It
On msdn, I saw Scott write a new view engine about MVC. I think it is very powerful and can effectively solve the current MVC view.CodeCompilation is cumbersome and is expected to be officially released.
[Original article] introducing "Razor"-A New View engine for ASP. NET
[Original article publication date] July 02,201 0 pm
One of the jobs my team is currently working on is to add a new view engine for ASP. NET.
ASP. net mvc has always sup
Tags: book title Update name Create Project class MEP get fieldLearn the ASP. NET Core Razor Programming series Catalog Learn ASP. NET Core Razor programming series One Learn ASP. NET Core Razor Programming series two--Add an entity Learn ASP. NET Core Razor Programming series three--Create a data table and create a pr
Another view engine of ASP. NET -- Razor
1. What is Razor?
If you know what ASPX is, I will tell you that Razor is another view engine like ASPX. When it comes to views, you will understand a lot. Since both view engines are MS, there must be a difference between the two view engines after the first and second view engines. Now let's get to know
Introducing "Razor" –a new view engine for ASP.net
One of the things my team has been working in has been a new view engine option for asp.net.
asp.net MVC has always supported the concept of "view engines" –which are the pluggable modules that implement different Template syntax options. The "default" view engine for ASP.net MVC today uses the same. aspx/.ascx/.master file templates as asp.net Web Forms. Other popular ASP.net MVC view engines used to
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.